import org.junit.Test;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

public class test01 {

    @Test
    public void test01() {
        int[] array = {
                2, 10, 8, 22, 34, 5, 12, 28, 21, 11
        };
        quickSort(array);

        String s = Arrays.toString(array);

        System.out.println(s);
    }

    public void quickSort(int[] array) {

        int borderIndex = array.length / 2;

        int border = array[borderIndex];


    }

    /**
     * 分解好的数组，无法合并，失败
     */
    public void quickSortFail(int[] array, int arrayLength) {
        /**
         * [10,8]
         * border = 8
         * leftArray = [] 所以会出现长度为0的情况
         * */
        if (arrayLength <= 1) {
            return;
        }
        int border = array[arrayLength - 1];

        System.out.println("这个border是：" + border);

        /**
         * 因为 比边界 border 小的元素个数不确定，所以按照最多来算
         * */
        int[] leftArray = new int[arrayLength - 1];

        int[] rightArray = new int[arrayLength - 1];

        int leftIndex = 0, rightIndex = 0;

        for (int i = 0; i < arrayLength; i++) {
            if (array[i] > border) {
                rightArray[rightIndex] = array[i];
                rightIndex++;
            } else if (array[i] < border) {
                leftArray[leftIndex] = array[i];
                leftIndex++;
            }
        }
        System.out.println(Arrays.toString(leftArray));
        System.out.println(Arrays.toString(rightArray));

        int i = 0;
        for (; i < leftIndex; i++) {
            array[i] = leftArray[i];
        }
        //已经加了
        //i++;

        array[i] = border;

        i++;

        for (int j = 0; j < rightIndex; j++) {
            array[i] = rightArray[j];
            i++;
        }

        /**
         * 因为 leftIndex 用的是++ 操作，循环4次 leftIndex 就是 4
         * */
        //quickSort(leftArray, leftIndex);
        //quickSort(rightArray, rightIndex);


    }
}
